package org.example.word;

import org.wickedsource.docxstamper.DocxStamper;
import org.wickedsource.docxstamper.DocxStamperConfiguration;
import org.wickedsource.docxstamper.replace.typeresolver.image.ImageResolver;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Base64;

public class DocxStamperUtil {

    public static void generateDocument(String templatePath, ReportData data, String outputPath) {
        // 创建配置
        DocxStamperConfiguration config = new DocxStamperConfiguration();
        // 创建 Stamper 实例
        DocxStamper<ReportData> stamper = new DocxStamper<>(config);
        try (InputStream template = new FileInputStream(templatePath);
             OutputStream out = new FileOutputStream(outputPath)) {

            // 填充模板并生成文档
            stamper.stamp(template, data, out);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void generateDocument(InputStream template, ReportData data, String outputPath) {
        // 创建配置
        DocxStamperConfiguration config = new DocxStamperConfiguration();
        // 创建 Stamper 实例
        DocxStamper<ReportData> stamper = new DocxStamper<>(config);
        try (OutputStream out = Files.newOutputStream(Paths.get(outputPath))) {
            // 填充模板并生成文档
            stamper.stamp(template, data, out);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
